package com.dcivision.lucene;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Auto thread to handle index action.
 * Use a staic Timer instance to schedule the index action run.
 * @author Administrator
 *
 */
public class IndexAutoTrigger {
  
  private static final Log log = LogFactory.getLog(IndexAutoTrigger.class);
  
  private static IndexAutoTask indexTask = null;
  
  /**
   * init schedule task to do index.
   *
   */
  public static void startIndexTask() {
    if (indexTask==null) {
      synchronized (IndexAutoTrigger.class) {
        if (indexTask==null) {
          indexTask = new IndexAutoTask();
          indexTask.start();
        }
      }
    }
  }
  
  /**
   * call the schedule 'TimerTask' action run.
   *
   */
  public synchronized static void indexImmediately() {
    if (indexTask==null) {
      startIndexTask();
    }else {
      try {
        indexTask.indexImmediately();
      }catch (Exception ex) {
        log.error(ex, ex);
      }
    }
  }

}
